package com.rongji.cms.tools.es.service.impl;

import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import com.rongji.cms.tools.es.domain.entity.CmsArticle;
import com.rongji.cms.tools.es.mapper.es.CmsArticleEsMapper;
import com.rongji.cms.tools.es.service.CmsArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yang
 * @date 2022/10/21 14:18
 * @description
 */

@Service
public class CmsArticleServiceImpl implements CmsArticleService {

    @Resource
    CmsArticleEsMapper articleMapper;

    @Override
    public int batchInsert(List<CmsArticle> cmsArticleList) {

        return articleMapper.insertBatch(cmsArticleList);
    }

    @Override
    public void batchDeleteByIds(List<String> arIds) {
        articleMapper.deleteBatchIds(arIds);
    }

    @Override
    public long searchNumByAllEq(Map<String, Object> map) {
        LambdaEsQueryWrapper<CmsArticle> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.allEq(map);
        return articleMapper.selectCount(wrapper);
    }

    @Override
    public List<CmsArticle> searchByAllEq(Map<String, Object> map) {
        LambdaEsQueryWrapper<CmsArticle> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.allEq(map);
        List<CmsArticle> list = articleMapper.selectList(wrapper);
        return list;
    }

    @Override
    public List<String> getArIds(Map<String, Object> map, int pageSize) {
        List<String> arIdList = new ArrayList<>();
        LambdaEsQueryWrapper<CmsArticle> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.allEq(map);
        wrapper.limit(pageSize);
        List<CmsArticle> cmsArticleList = articleMapper.selectList(wrapper);
        for (CmsArticle cmsArticle : cmsArticleList) {
            arIdList.add(cmsArticle.getId());
        }
        return arIdList;
    }
}
